<cfcomponent output="false" name="Monitor Utility">
	<cfscript>
		variables.serverFilePath = "";
	</cfscript>
	<cffunction name="init">
		<cfreturn this />
	</cffunction>
	<cffunction access="public" name="writeLogToFile" returntype="boolean" output="false">
		<cfargument name="FilePath" type="String" required="true" hint="path on server where you want file to be written" />
		<cfargument name="VariableToDump" type="Any" required="true" hint="Variable to dump to file"/>
		<cfargument name="OverwriteFlag" type="Boolean" default="false"/>
		<cfargument name="Type" type="String" default="COMPLEX" hint="COMPLEX,ARRAY,STRUCT,QUERY|FILE,CFM,CFMFILE" />
		<cfscript>
			var result = false;
			variables.serverFilePath = arguments.FilePath;
		</cfscript>
		<cftry>
			<cfsavecontent variable="fileContent">
				<cfoutput>
					<cfswitch expression="#uCase(arguments.Type)#">
						
						<cfcase value="HTML,SIMPLE">
							<cfoutput>#HTMLDecodeFormat(VariableToDump)#</cfoutput>
						</cfcase>
						<cfcase value="FILE,CFM,CFMFILE">
							<cfinclude template="#VariableToDump#" />		
						</cfcase>
						<cfdefaultcase>
							<cfdump var="#VariableToDump#" />
						</cfdefaultcase>
					</cfswitch>
					
					<br />
				</cfoutput>
			</cfsavecontent>
			
			<cfif arguments.OverwriteFlag eq true>
				<cffile file="#arguments.filePath#" action="write" output="#fileContent#" />
			<cfelse>
				<cffile file="#arguments.filePath#" action="append" output="#fileContent#" />
			</cfif>
			
			<cfset result = true />
			<cfcatch type="any">
				<cffile file="#arguments.filePath#" action="append" output="<h2>ERROR</h2>#cfcatch.message#<br />#cfcatch.detail#" />
				<cfset result = false />
			</cfcatch>
		</cftry>

		<cfreturn result />
	</cffunction>
	
	
	<cffunction name="HTMLDecodeFormat" access="public" returntype="any">
		<cfargument name="txt" required="true" type="String"/>
		
		<cfset new_txt = "<textarea rows='20' cols='100'>" & rereplace(reReplace(arguments.txt,"&lt;", "<", "ALL"),"&gt;", ">#chr(10)##chr(13)#", "ALL") & "</textarea>"/>
		
		<cfreturn new_txt />
	</cffunction>
</cfcomponent>